package com.wkcto.springcloud.controller;

import com.netflix.zuul.context.RequestContext;
import com.netflix.zuul.exception.ZuulException;
import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 全局路由异常类
 */
@RestController
public class ErrorHandlerController implements ErrorController {
    /**
     * 出现异常时进入该方法，并由下面的方法处理
     * @return
     */
    @Override
    public String getErrorPath() {
        //将之前错误过滤器注释掉
        return "error";
    }

    @RequestMapping("/error")
    public Object Error(){
        RequestContext ctx = RequestContext.getCurrentContext();
        ZuulException exception = (ZuulException) ctx.getThrowable();
        return exception.nStatusCode+"--"+exception.getMessage();
    }
}
